﻿// JScript 文件

// JScript 文件
//获取分页
function funGetPaginationHtml()
{
    this.GetPaginationHtml=function( nTotalCount,nShowPages,eventName)
    {
        var tHtml = '';
        var nStartPage = Math.round(nShowPages / 2 - 0.5);
        //总页数
        var cPageCount = funGetHowManyPageCount(nTotalCount);
        var prepage=isFirstPage(g_Page);
        var nextpage=islastPage(g_Page,cPageCount);
        if( cPageCount > 1 )
        {
            //开始页        
            var cStartPageIndex = 1;
            //结束页
            var cEndPageIndex = cPageCount;
            
            var starthtm='';
            var endhtm='';
            if( cPageCount > nShowPages )
            { 
                if( ( g_Page - nStartPage ) > 1 )
                {  
                 cStartPageIndex = g_Page - nStartPage; 
                   if(  cStartPageIndex-1 >1)
                   {
                    starthtm='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'(1)">1</span>';
                    starthtm+='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: none;" onclick="'+eventName+'('+(g_Page-1)+')">...</span>';
                   }
                   else
                   {
                    starthtm='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'(1)">1</span>';
                   }
                   
                }
                if( ( cStartPageIndex + nShowPages - 1 ) < cPageCount )
                {   
                     cEndPageIndex = cStartPageIndex + nShowPages - 1;
                      if( cPageCount-cEndPageIndex>1 )
                     { 
                        endhtm='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: none;" onclick="'+eventName+'('+(g_Page+1)+')">...</span>';
                        endhtm+='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'('+cPageCount+')">'+cPageCount+'</span>';
                     }
                     else
                     {
                        endhtm='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'('+cPageCount+')">'+cPageCount+'</span>';
                     }
                }
                else
                { 
                
                    if( ( cEndPageIndex - nShowPages + 1 ) > 0 
                       && ( cEndPageIndex - nShowPages + 1 ) < cStartPageIndex 
                       ){
                           cStartPageIndex = cEndPageIndex - nShowPages + 1;
                       }
                   if(  cStartPageIndex-1 >1)
                   {
                    starthtm='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'(1)">1</span>';
                    starthtm+='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: none;" onclick="'+eventName+'('+(g_Page-1)+')">...</span>';
                   }
                   else
                   {
                    starthtm='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'(1)">1</span>';
                   }
                   
                }
            } 
            tHtml +='<div><table><tr height=22px>';
            //首页
            tHtml +='<td style="vertical-align: middle; text-align: center;background-color: #f7fdff;border-right: #9cc3d9 1px solid; border-top: #9cc3d9 1px solid; border-left: #9cc3d9 1px solid; border-bottom: #9cc3d9 1px solid;">';
            tHtml +='&nbsp;<a href="javascript:void(0)" onclick="'+eventName+'(1)">首页</a>&nbsp;</td>';
            //分格
             //上一页
            tHtml +='<td style="vertical-align: middle; text-align: center;background-color: #f7fdff;border-right: #9cc3d9 1px solid; border-top: #9cc3d9 1px solid; border-left: #9cc3d9 1px solid; border-bottom: #9cc3d9 1px solid;">';
            if (g_Page==1)
            {
                tHtml +='&nbsp;上一页&nbsp;';
            }
            else
            {
                tHtml +='&nbsp;<a href="javascript:void(0)" onclick="'+eventName+'('+prepage+')">上一页</a>&nbsp;';
            }
            
            var htm=starthtm;
             for( var cIndex = (cStartPageIndex - 1); cIndex < cEndPageIndex;cIndex++ )
             {
                if( cIndex == (g_Page - 1 ) ){//当前选中项
                    htm += '&nbsp;&nbsp;<span><font color="red">'
                           + ( cIndex + 1 )
                           + '</font><span>';
                }
                else
                {
                    htm += '&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'( '
                           + ( cIndex + 1 )
                           + ' )" >'
                           + ( cIndex + 1 )
                           + '</span>';
                }
             }
             htm+=endhtm;
            tHtml +='<td width=3px>'+htm+'</td>';
           
            //分格
            tHtml +='<td width=3px></td>';
            //下一页
            tHtml +='<td style="vertical-align: middle; text-align: center;background-color: #f7fdff;border-right: #9cc3d9 1px solid; border-top: #9cc3d9 1px solid; border-left: #9cc3d9 1px solid; border-bottom: #9cc3d9 1px solid;">';
            if (g_Page==cPageCount)
            {
                tHtml +='&nbsp;下一页&nbsp;';
            }
            else
            {
                tHtml +='&nbsp;<a href="javascript:void(0)" onclick="'+eventName+'('+nextpage+')">下一页</a>&nbsp;';
            }
            //分格
            tHtml +='<td width=3px></td>';
            //尾页
            tHtml +='<td style="vertical-align: middle; text-align: center;background-color: #f7fdff;border-right: #9cc3d9 1px solid; border-top: #9cc3d9 1px solid; border-left: #9cc3d9 1px solid; border-bottom: #9cc3d9 1px solid;">';
            tHtml +='&nbsp;<a href="javascript:void(0)" onclick="'+eventName+'('+cPageCount+')">尾页</a>&nbsp;</td>';
            //分格
            tHtml +='<td width=3px></td>';
            //页码
            tHtml +='<td style="vertical-align: middle; text-align: center;background-color: #f7fdff;border-right: #9cc3d9 1px solid; border-top: #9cc3d9 1px solid; border-left: #9cc3d9 1px solid; border-bottom: #9cc3d9 1px solid;">';
            tHtml +='<input onkeyup="checktxt(this)" value='+g_Page+' id="pagenum" type=text style="width=30px;vertical-align: middle; text-align: center;background-color:white;border-right:white 1px solid; border-top:white 1px solid; border-left:white 1px solid; border-bottom:white 1px solid;"></td>';
            //分格
            tHtml +='<td width=3px></td>';
            //GO
            tHtml +='<td style="vertical-align: middle; text-align: center;background-color: #f7fdff;border-right: #9cc3d9 1px solid; border-top: #9cc3d9 1px solid; border-left: #9cc3d9 1px solid; border-bottom: #9cc3d9 1px solid;">';
            tHtml +='&nbsp;<a href="javascript:void(0)" onclick="showPageByNum()">GO</a>&nbsp;</td>';
            //分格
            tHtml +='<td width=3px></td>';
            //总页
            tHtml +='<td style="vertical-align: middle; text-align: center;background-color: #f7fdff;border-right: #9cc3d9 1px solid; border-top: #9cc3d9 1px solid; border-left: #9cc3d9 1px solid; border-bottom: #9cc3d9 1px solid;">';
            tHtml +='&nbsp;&nbsp;'+g_Page+'/'+cPageCount+'页&nbsp;&nbsp;</td>';                        
        }    

             
            
            
//            tHtml +='</tr></table></div>';
//            
//            tHtml += '<div ><table><tr><td style="border-right: #9cc3d9 1px solid; border-top: #9cc3d9 1px solid; border-left: #9cc3d9 1px solid; border-bottom: #9cc3d9 1px solid;">';
//            if(g_Page==1)
//            {
//               tHtml += '<span ><span >&nbsp;&nbsp;</span></span>'; 
//            }
//            else
//            {
//                tHtml += '<a><span  style="cursor:pointer;text-decoration: none;" onclick="'+eventName+'( '
//                       + prepage
//                       + ' )" >&nbsp;&nbsp;</span></a>';
//             }
//             for( var cIndex = (cStartPageIndex - 1); cIndex < cEndPageIndex;cIndex++ )
//             {
//                if( cIndex == (g_Page - 1 ) ){//当前选中项
//                    tHtml += '<span class="over"><font color="red">'
//                           + ( cIndex + 1 )
//                           + '</font></span>';
//                }
//                else
//                {
//                    tHtml += '<a><span  style="cursor:pointer;text-decoration: none;" onclick="'+eventName+'( '
//                           + ( cIndex + 1 )
//                           + ' )" >'
//                           + ( cIndex + 1 )
//                           + '</span></a>';
//                }
//             }
//        if(g_Page==cPageCount)
//        {
//         tHtml += '<span class="noclick"><span class="nextnoclick">&nbsp;&nbsp;</span></span>';
//        }
//       else
//       {
//           tHtml += '<a><span class="next" style="cursor:pointer;text-decoration:none;" onclick="'+eventName+'( '
//                       + nextpage
//                       + ' )" >&nbsp;&nbsp;</span></a>';
//                   
//         }
//                         tHtml += '<font color="Gray"><input onkeyup="checktxt(this)" id="pagenum" type="text" style="width:20px;height:18px;"/></font>';
//                         tHtml += '<input id="go" type="button"  onclick="showPageByNum()"  style="cursor:hand;width: 20px; height: 20px; border-right: gainsboro 0px solid; border-top: gainsboro 0px solid; border-left: gainsboro 0px solid; border-bottom: gainsboro 0px solid; border-collapse: collapse; background: url(../../image/go.gif) fixed no-repeat center center;" />';
////                         tHtml += '<a href="#" onclick="showPageByNum()"><img id="go" src="../../image/go_1.gif" style="width:10px;height:18px;"></img></a>';
//                         tHtml += '&nbsp;<font color=" #0066A7">'+g_Page+'/'+cPageCount+'</font>';
//                         tHtml += '</td></tr></table></div>'
//        }
        return tHtml;
    }
    
    
    this.GetPaginationHtml2 = function(nTotalCount,nShowPages,eventName)
    {
        var tHtml = '';
        var nStartPage = Math.round(nShowPages / 2 - 0.5);
        //总页数
        var cPageCount = funGetHowManyPageCount(nTotalCount);
        var prepage=isFirstPage(g_Page);
        var nextpage=islastPage(g_Page,cPageCount);
        if( cPageCount > 1 )
        {
            //开始页        
            var cStartPageIndex = 1;
            //结束页
            var cEndPageIndex = cPageCount;
            
            var starthtm='';
            var endhtm='';
            if( cPageCount > nShowPages )
            { 
                if( ( g_Page - nStartPage ) > 1 )
                {  
                 cStartPageIndex = g_Page - nStartPage; 
                   if(  cStartPageIndex-1 >1)
                   {
                    starthtm='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'(1)">1</span>';
                    starthtm+='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: none;" onclick="'+eventName+'('+(g_Page-1)+')">...</span>';
                   }
                   else
                   {
                    starthtm='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'(1)">1</span>';
                   }
                   
                }
                if( ( cStartPageIndex + nShowPages - 1 ) < cPageCount )
                {   
                     cEndPageIndex = cStartPageIndex + nShowPages - 1;
                      if( cPageCount-cEndPageIndex>1 )
                     { 
                        endhtm='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: none;" onclick="'+eventName+'('+(g_Page+1)+')">...</span>';
                        endhtm+='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'('+cPageCount+')">'+cPageCount+'</span>';
                     }
                     else
                     {
                        endhtm='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'('+cPageCount+')">'+cPageCount+'</span>';
                     }
                }
                else
                { 
                
                    if( ( cEndPageIndex - nShowPages + 1 ) > 0 
                       && ( cEndPageIndex - nShowPages + 1 ) < cStartPageIndex 
                       ){
                           cStartPageIndex = cEndPageIndex - nShowPages + 1;
                       }
                   if(  cStartPageIndex-1 >1)
                   {
                    starthtm='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'(1)">1</span>';
                    starthtm+='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: none;" onclick="'+eventName+'('+(g_Page-1)+')">...</span>';
                   }
                   else
                   {
                    starthtm='&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'(1)">1</span>';
                   }
                   
                }
            } 
            tHtml +='<div><table><tr height=22px>';
            //首页
            tHtml +='<td style="vertical-align: middle; text-align: center;background-color: #f7fdff;border-right: #9cc3d9 1px solid; border-top: #9cc3d9 1px solid; border-left: #9cc3d9 1px solid; border-bottom: #9cc3d9 1px solid;">';
            tHtml +='&nbsp;<a href="javascript:void(0)" onclick="'+eventName+'(1)">首页</a>&nbsp;</td>';

            //上一页
            tHtml +='<td style="vertical-align: middle; text-align: center;background-color: #f7fdff;border-right: #9cc3d9 1px solid; border-top: #9cc3d9 1px solid; border-left: #9cc3d9 1px solid; border-bottom: #9cc3d9 1px solid;">';
            if (g_Page==1)
            {
                tHtml +='&nbsp;上一页&nbsp;';
            }
            else
            {
                tHtml +='&nbsp;<a href="javascript:void(0)" onclick="'+eventName+'('+prepage+')">上一页</a>&nbsp;';
            }
            
            var htm=starthtm;
             for( var cIndex = (cStartPageIndex - 1); cIndex < cEndPageIndex;cIndex++ )
             {
                if( cIndex == (g_Page - 1 ) ){//当前选中项
                    htm += '&nbsp;&nbsp;<span><font color="red">'
                           + ( cIndex + 1 )
                           + '</font><span>';
                }
                else
                {
                    htm += '&nbsp;&nbsp;<span style="cursor:pointer;text-decoration: underline;" onclick="'+eventName+'( '
                           + ( cIndex + 1 )
                           + ' )" >'
                           + ( cIndex + 1 )
                           + '</span>';
                }
             }
            htm+=endhtm;
            tHtml +='<td width=3px>'+htm+'</td>';
          
            //下一页
            tHtml +='<td style="vertical-align: middle; text-align: center;background-color: #f7fdff;border-right: #9cc3d9 1px solid; border-top: #9cc3d9 1px solid; border-left: #9cc3d9 1px solid; border-bottom: #9cc3d9 1px solid;">';
            if (g_Page==cPageCount)
            {
                tHtml +='&nbsp;下一页&nbsp;';
            }
            else
            {
                tHtml +='&nbsp;<a href="javascript:void(0)" onclick="'+eventName+'('+nextpage+')">下一页</a>&nbsp;';
            }

            //尾页
            tHtml +='<td style="vertical-align: middle; text-align: center;background-color: #f7fdff;border-right: #9cc3d9 1px solid; border-top: #9cc3d9 1px solid; border-left: #9cc3d9 1px solid; border-bottom: #9cc3d9 1px solid;">';
            tHtml +='&nbsp;<a href="javascript:void(0)" onclick="'+eventName+'('+cPageCount+')">尾页</a>&nbsp;</td>';
                                 
        }    
        return tHtml;
    }
    
    
}


//检查是否录入数字
function   checktxt(point){   
      var   str   =  document.getElementById(point.id).value;   
      var   reg   =   new   RegExp("(^[1-9]+[0-9]*$)"); 
      if(!reg.test(str))
      {
      alert("请输入大于0的整数");
      document.getElementById(point.id).value="";
      //document.getElementById(point.id).value=str.substr(0,str.length-1);
      }
      if (event.keyCode==13)
      {
        showPageByNum();
      }
  }   
function isFirstPage(page)
{    
   var page=((page-1)>0)?(page-1):1;
   return page;
}
function islastPage(page,pagecount)
{
   var page = ( parseInt(page) + 1 > pagecount) ? pagecount : parseInt(page) + 1;
   return page;
}

///通过总记录数计算总共的页数
function funGetHowManyPageCount( nTotalCount )
{
    if( nTotalCount <=0 )
    {
        return 0;
    }
    else
    {
        var tPageCount = 0;
        if( ( nTotalCount %g_PageSize ) == 0)
        {
            tPageCount = nTotalCount / g_PageSize;
        }
        else
        {
            tPageCount = Math.ceil( nTotalCount / g_PageSize );
        } 
        return tPageCount;
    }
}

